Skip to content

Support MPS Backend also on iOS < 16 (#9089) #9095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

f-meloni
Copy link
Contributor

@f-meloni f-meloni commented Mar 10, 2025

Summary: Pull Request resolved: #9089

Differential Revision: D70795041

The MPS backend currently does not compile for iOS < 16.
I have added some conditional code to make it usable anyway

@f-meloni f-meloni requested a review from cccclai as a code owner March 10, 2025 18:09
Copy link

pytorch-bot bot commented Mar 10, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9095

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 5421a77 with merge base 4c54bab (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 10, 2025
@f-meloni f-meloni changed the title Add MPS Backend (#9089) Support MPS Backend also on iOS < 16 (#9089) Mar 10, 2025
@f-meloni
Copy link
Contributor Author

cc @DenisVieriu97

@f-meloni
Copy link
Contributor Author

@pytorchbot label "topic: not user facing"

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70795041

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70795041

@shoumikhin
Copy link
Contributor

@DenisVieriu97 please take a look!

@shoumikhin
Copy link
Contributor

@DenisVieriu97 shall we just merge it?

Debug, "%s %d: %d",
__FUNCTION__, graphNode->input1_id(), graphNode->output_id()
);
if (@available(iOS 16, macOS 13, *)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return an error for the else statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the if is not true, then we do not do _idToMPSGraphTensor[graphNode->output_id()] = ... which I think would then not set the tensor value and that would fail the prediction, but only if this is used.
Do you think we should return Error::notSupported or something like that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just we can handle it in a non-fatal way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cccclai Is the latest version OK?
Thank you for the review :)

f-meloni pushed a commit to f-meloni/executorch that referenced this pull request Mar 18, 2025
Summary:


Differential Revision: D70795041
f-meloni pushed a commit to f-meloni/executorch that referenced this pull request Mar 18, 2025
Summary:


Differential Revision: D70795041
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70795041

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70795041

f-meloni pushed a commit to f-meloni/executorch that referenced this pull request Mar 18, 2025
Summary:
Pull Request resolved: pytorch#9095

Pull Request resolved: pytorch#9089

Differential Revision: D70795041

return Error::Ok;
} else {
return Error::NotSupported;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, one minor thing - can you add an error log here like

ET_LOG(Error, "...")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, and I also changed the requirements to iOS 15.4 and MacOS 12.3

f-meloni pushed a commit to f-meloni/executorch that referenced this pull request Mar 19, 2025
Summary:


Reviewed By: cccclai

Differential Revision: D70795041
f-meloni pushed a commit to f-meloni/executorch that referenced this pull request Mar 19, 2025
Summary:


Reviewed By: cccclai

Differential Revision: D70795041
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70795041

Summary:
Pull Request resolved: pytorch#9095

Pull Request resolved: pytorch#9089

Reviewed By: cccclai

Differential Revision: D70795041
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D70795041

Copy link
Collaborator

@DenisVieriu97 DenisVieriu97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thanks @f-meloni for the changes

#if defined(__MAC_13_0)
if (macOS13Plus) {
languageVersion = MTLLanguageVersion3_0;
if (@available(iOS 16, macOS 13, *)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the change

Debug, "%s %d: %d",
__FUNCTION__, graphNode->input1_id(), graphNode->output_id()
);
if (@available(iOS 15.4, macOS 12.3, *)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@facebook-github-bot facebook-github-bot merged commit a699b5b into pytorch:main Mar 19, 2025
89 checks passed
oscarandersson8218 pushed a commit to oscarandersson8218/executorch that referenced this pull request Mar 21, 2025
Differential Revision: D70795041

Pull Request resolved: pytorch#9095
DannyYuyang-quic pushed a commit to CodeLinaro/executorch that referenced this pull request Apr 2, 2025
Differential Revision: D70795041

Pull Request resolved: pytorch#9095
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants